package com.mdjnu.controller;

import com.mdjnu.pojo.Categories;
import com.mdjnu.pojo.Result;
import com.mdjnu.service.CategoriesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/categories")
public class CategoriesController {
    // 注入service
    @Autowired
    private CategoriesService categoriesService;
    // 获取所有分类
    /**
     * 获取所有分类
     * @return Result
     */
    @GetMapping("/getAllCategories")
    public Result  getAllCategories()
    // 返回结果
    {
        List<Categories> categoriesList=categoriesService.getAllCategories();
        // 判断是否为空
        if (categoriesList!=null){
            return Result.success(categoriesList);
        }
        else {
            return Result.error("获取失败");
        }
    }



}
